using System;
using System.Collections.Generic;

using MethodChaining.MFComputer.Model;



namespace MethodChaining.MFComputer.Builders
{
	public class ComputerBuilder
	{
		private Processor _processor = Processor.WhoCares;
		private int _numberOfCores;
		private readonly List<Disk> _loadedDisks = new List<Disk>();





		public static implicit operator Computer( ComputerBuilder builder )
		{
			return new Computer( builder._processor, builder._numberOfCores, builder._loadedDisks );
		}





		public DiskBuilder WithDisk
		{
			get { return new DiskBuilder( this ); }
		}



		public Computer Done
		{
			get { return this; }
		}



		public ComputerBuilder IsQuadCore
		{
			get { return WithCores( 4 ); }
		}



		public ComputerBuilder IsDualCore
		{
			get { return WithCores( 2 ); }
		}





		public ComputerBuilder OfType( Processor value )
		{
			_processor = value;
			return this;
		}





		public ComputerBuilder WithCores( int numberOfCores )
		{
			if( ( _numberOfCores != 0 ) && ( _numberOfCores != numberOfCores ) )
				throw new ArgumentException( String.Format( "Already set number of cores to {0} - attempt to set it to {1} is invalid!", _numberOfCores, numberOfCores ) );

			_numberOfCores = numberOfCores;
			return this;
		}





		internal void AddDisk( Disk disk )
		{
			_loadedDisks.Add( disk );
		}
	}
}